﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace test2
{
    class Program
    {
        static void Main(string[] args)
        {
            Rule rule = new Rule();
            Tiger tiger = new Tiger("tiger", (int)AnimalPriority.TigerPriority);
            Tabra tabra = new Tabra("tabra", (int)AnimalPriority.TabraPriority);
            Owl owl = new Owl("owl", (int)AnimalPriority.OwlPriority);
            Cat cat = new Cat("cat", (int)AnimalPriority.CatPriority);

            cat.Activity(rule);
            tiger.Calling(rule);
            tabra.Activity(rule);
            owl.Activity(rule);
            
            System.Console.ReadLine();
        }
    }
    public enum AnimalPriority 
    { 
        TigerPriority = 1,
        TabraPriority = 2,
        OwlPriority = 3,
        CatPriority = 3,
    }

    public class Rule
    {
        private bool voice;
        private int maxPriority = 100;
        public int MaxPriority 
        {
            get { return maxPriority; }
            set { maxPriority = value; }
        }
        public bool Voice 
        {
            get { return voice; }
            set { voice = value; }
        }

        public void Updata(int animal)
        {
            if (animal < maxPriority)
                this.maxPriority = animal;
        }
    }
    public interface IActivity
    {
        void Runing();
        void Eating();
        void Calling(Rule rule);
        void Alerting();
        void Activity(Rule rule);
    }
    public class Animal : IActivity
    {
        private String animalName;
        private int priority;
        public String AnimalName
       {
            get { return animalName; }
            set { animalName = value; }
        }
        public int Priority 
        {
            get { return priority; }
            set { priority = value; }
        }
        public void Runing()  { System.Console.WriteLine("run away..."); }
        public void Eating()  { System.Console.WriteLine("eating..."); }
        public void Alerting() { System.Console.WriteLine("alerting..."); }
        public void Calling(Rule rule) 
        {
            rule.Updata(this.priority);
            rule.Voice = true;
            System.Console.WriteLine(AnimalName + " ");
            System.Console.WriteLine("calling...");
        }
      
        public void Activity(Rule rule)
        {
            System.Console.WriteLine(AnimalName + " ");
            if (rule.Voice == true) 
                Alerting();
            else if (Priority > rule.MaxPriority)
                Runing();
            else
                Eating();
        }
    }
    public class Tiger : Animal
    {
        public Tiger(String name, int animal)
        {
            AnimalName = name;
            Priority = animal;
        }
    }
    public class Tabra : Animal
    {
        public Tabra(String name, int animal)
        {
            AnimalName = name;
            Priority = animal;
        }
    }
    public class Owl : Animal
    {
        public Owl(String name, int animal)
        {
            AnimalName = name;
            Priority = animal;
        }
    }
    public class Cat : Animal
    {
        public Cat(String name, int animal)
        {
            AnimalName = name;
            Priority = animal;
        }
    }
}
